<!-- 自动化实验-实验数据管理 -->
<template>
  <!-- 顶部搜索区 -->
  <div class="main-app" v-loading="loading">
    <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-top: 5px; margin-bottom: 15px;">
      <el-breadcrumb-item :to="{path:'/'}">{{$t('common.nav.home')}}</el-breadcrumb-item>
      <el-breadcrumb-item>{{$t('common.nav.automationExperiment')}}</el-breadcrumb-item>
      <el-breadcrumb-item>{{$t('common.nav.experimentDataManage')}}</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 数据列表区 -->
    <el-card class="box-card" style="margin-top: 1%;">
      <!-- 搜索条件 -->
      <el-form :inline="true" :model="searchParam" class="form-inline">
        <el-form-item :label="$t('common.label.expName')+':'">
          <el-input v-model="searchParam.name" clearable />
        </el-form-item>
        <el-form-item :label="$t('common.label.expNumber')+':'">
          <el-input v-model="searchParam.number" clearable />
        </el-form-item>
        <el-form-item :label="$t('common.label.expStatus')+':'">
          <el-select v-model="searchParam.status" :placeholder="$t('common.placeholder.pleaseSelect')" clearable>
            <el-option :label="$t('common.label.inQueue')" value="10" />
            <el-option :label="$t('common.label.inProgress')" value="20" />
            <el-option :label="$t('common.label.completed')" value="30" />
            <el-option :label="$t('common.label.terminated')" value="40" />
            <el-option :label="$t('common.label.canceled')" value="50" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="search">{{$t('common.button.search')}}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-refresh-right" @click="reset">{{$t('common.button.reset')}}</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 数据表格 -->
    <div class="show-result">
      <div class="table">
        <el-table id="table" ref="multipleTable" tooltip-effect="dark" stripe style="width: 100%" :data="tableData" @selection-change="handleSelectionChange">
          <el-table-column class="handle" type="selection" width="55" align="center"/>
          <el-table-column prop="name" :label="$t('common.label.expName')" align="center"/>
          <el-table-column prop="number" :label="$t('common.label.expNumber')" align="center"/>
          <el-table-column prop="status" :label="$t('common.label.expStatus')" width="120" align="center">
            <template slot-scope="scope">
              <el-tag style="width: 100%; text-align: center" effect="dark" :class="'bg-' + scope.row.statusColor">{{ scope.row.status }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="expStartTime" :label="$t('common.label.expStartTime')" align="center">
            <template slot-scope="scope">
              {{ scope.row.expStartTime | parseDate }}
            </template>
          </el-table-column>
          <el-table-column prop="expEndTime" :label="$t('common.label.expEndTime')" align="center">
            <template slot-scope="scope">
              {{ scope.row.expEndTime | parseDate }}
            </template>
          </el-table-column>
          <el-table-column prop="createUserName" :label="$t('common.label.createUserName')" align="center"/>
          <el-table-column prop="createTime" :label="$t('common.label.createTime')" width="180" align="center">
            <template slot-scope="scope">
              {{ scope.row.createTime | parseDate }}
            </template>
          </el-table-column>
          <el-table-column fixed="right" :label="$t('common.label.operate')" align="center" width="200">
            <template slot-scope="scope">
              <el-button-group>
                <el-button type="primary" size="mini" @click="operation($t('common.button.detail'), scope.row)">{{$t('common.button.detail')}}</el-button>
              </el-button-group>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 列表底部分页按钮 -->
      <div class="page">
        <el-pagination background layout="total, prev, pager, next, sizes"
          :total="total"
          :current-page.sync="currentPage"
          :page-sizes="[5, 10, 20, 50, 100]"
          :page-size="pageSize"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { pageMixin } from "../../../mixins/index";
import {
  ExperimentRecordList
} from "../../../api/record.js";
export default {
  // 页面公共变量
  data() {
    return {
      searchParam: {
        name: "",
        number: "",
        status: ""
      },                            // 搜索条件参数
      dialogVisible: false,         // 是否隐藏提示框
    };
  },
  // 页面创建完成事件
  async created() {
    this.init();
  },
  // 数据过滤器
  filters: {
    // 转换日期显示格式
    parseDate(value) {
      if (value) {
        return value.replace("T", " ");
      }
    },
  },
  // 表格分页属性配置
  mixins: [pageMixin],
  // 页面相关方法
  methods: {
    // 初始化加载事件
    async init() {
      this.loading = true;        // 打开加载框

      // 获取列表数据
      const { data, count } = await ExperimentRecordList({
        page: this.currentPage,
        limit: this.pageSize,
        Name: this.searchParam.name,
        Number: this.searchParam.number,
        Status: this.searchParam.status
      });
      this.tableData = data;      // 设置表格数据源
      // 转换表格数据源部分字段显示
      this.tableData.forEach((item) => {
        switch (item.status) {
          case "10":
            item.status = this.$t('common.label.inQueue');
            item.statusColor = "blue";
            break;
          case "20":
            item.status = this.$t('common.label.inProgress');
            item.statusColor = "green";
            break;
          case "30":
            item.status = this.$t('common.label.completed');
            item.statusColor = "grey";
            break;
          case "40":
            item.status = this.$t('common.label.terminated');
            item.statusColor = "red";
            break;
          case "50":
            item.status = this.$t('common.label.canceled');
            item.statusColor = "yellow";
            break;
        }
        if (item.expStartTime === null) {
          item.expStartTime = '---';
        }
        if (item.expEndTime === null) {
          item.expEndTime = '---';
        }
      });
      this.total = count;         // 设置表格总数据量

      this.loading = false;       // 关闭加载框
    },
    // 表格重置事件
    async reset() {
      this.searchParam = {
        name: "",
        number: "",
        status: ""
      };
      await this.init();
    },
    // 操作功能按钮点击事件
    operation(value, row) {
      switch (value) {
        // 查看详情
        case this.$t('common.button.detail'):
          this.$router.push(`experiment_data/detail/${row.id}`);
          break;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
// 顶部按钮绝对定位
.formbtn { text-align: right; }
// 数据表格区样式
.show-result { margin-top: 1%; }
/* 操作项开关样式 */
::v-deep .switch .el-switch__label { position: absolute; display: none; color: #fff; }
/* 打开时文字位置设置 */
::v-deep .switch .el-switch__label--right { z-index: 1; right: 5px; }
/* 关闭时文字位置设置 */
::v-deep .switch .el-switch__label--left { z-index: 1; left: 8px; }
/* 显示文字 */
::v-deep .switch .el-switch__label.is-active { display: block; }
::v-deep .switch.el-switch .el-switch__core,
::v-deep .el-switch .el-switch__label { width: 60px !important; }
/* 表格隔行换色样式 */
::v-deep .el-table--striped .el-table__body tr.el-table__row--striped td { background-color: #F2F2F2; }
/* 表格数据行高 */
::v-deep .el-table td { padding: 8px 0px; }
/* 表头背景色样式 */
::v-deep .el-table th{ background-color: #DBEDEF !important; }
/* 表头数据行内线样式 */
::v-deep .el-table td,.building-top .el-table th.is-leaf { border-bottom: 0px; }
/* 自定义提示框样式 */
.dialog_diy {
  ::v-deep .el-dialog__wrapper {
    .el-dialog {
      .el-dialog__body { padding: 0px; }
      .el-dialog__header { padding: 0px; }
      .el-dialog__headerbtn { top: 5px; right: 5px; padding-top: 10px; }
      .el-dialog__headerbtn .el-dialog__close { color: #fff; height: 30px; width: 35px; }
      .el-dialog__headerbtn .el-dialog__close:hover { color: gray; }
    }
  }
}
// 区域标题样式
.titie-bar {
  width: 4px;
  height: 32px;
  border-radius: 2px;
  background-color: rgba(61, 171, 175, 1);
  margin: 5px 0 5px 0;
}
.titie-bar span {
  color: #0A0A0A;
  width: 80px;
  font-size: 22px;
  line-height: 32px;
  white-space: nowrap;
  overflow-wrap: break-word;
  margin-left: 15px;
}

// 设备状态区域样式
.device-status-panal {
  height: 400px;
  border-radius: 8px;
  box-shadow: 0px 2px 6px 0px rgba(39, 122, 160, 0.09);
  background-size: contain;
  background-position: center center;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
}
.device-status-panal-bg {
  background-image: url(../../../assets/icon/automation_experiment/task_overview/device_status_bg.png);
}

// 实景监控按钮样式
.monitor-btn {
  width: 140px;
  height: 40px;
  background-color: rgba(61, 171, 175, 1);
  border: 1px solid rgba(255, 255, 255, 1);
  box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.05);
  border-radius: 0px 8px 0px 16px;
  text-align: right;
  margin-top: -22px;
  margin-left: 35vw;
  margin-right: auto;
  display: flex;
  flex-direction: row;

  img {
    width: 24px;
    height: 24px;
    margin: 9px 0 0 24px;
  }

  span {
    width: 64px;
    height: 22px;
    color: rgba(255, 255, 255, 1);
    font-size: 16px;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
    overflow-wrap: break-word;
    line-height: 22px;
    margin: 9px 24px 0 0;
  }
}

// 统计区域样式
.statistics-panal {
  border-radius: 8px;
  box-shadow: 0px 2px 6px 0px rgba(39, 122, 160, 0.09);
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
}
.statistics-panal-bg-1 {
  background-image: url(../../../assets/icon/automation_experiment/task_overview/panal_bg_1.png);
}
.statistics-panal-bg-2 {
  background-image: url(../../../assets/icon/automation_experiment/task_overview/panal_bg_2.png);
}

// 设备工作统计区域样式
.work-statistics-panal {
  text-align: left;
  font-weight: 500;
  white-space: nowrap;
  overflow-wrap: break-word;

  .title {
    color: rgba(51, 51, 51, 1);
    width: 200px;
    height: 28px;
    font-size: 20px;
    line-height: 80px;
  }
  .content{
    color: rgba(63, 171, 175, 1);
    font-size: 40px;
    font-weight: 500;
    line-height: 110px;

    span:nth-of-type(2),
    span:nth-of-type(4),
    span:nth-of-type(6) {
      font-size: 24px;
    }
  }
}
</style>
